// socket mixins
/*
  handleAction: 监听消息方法
  sendMsg： 发送消息
  initWS 初始化
  this.initWS({
    // path: this.socketPath  使用path 访问本地服务器  需要代理
    // url:'ws://47.111.15.81:8087/QuanYou/ws/global/'+this.userId 直接通过 url 访问
  });
*/
import { mapGetters, mapActions } from 'vuex'

export default {
  watch: {
    msgCount() {
      if (this.handleAction) {
        this.handleAction(JSON.parse(this.msg))
      }
    }
  },
  computed: {
    ...mapGetters({
      msg: 'ws/msg',
      msgCount: 'ws/msgCount',
      userId: 'user/userId'
    }),
    socketPath() {
      return `${process.env.VUE_APP_API_PREFIX_URL}${process.env.VUE_APP_SOCKET_URL}/${this.userId}`
    }
  },
  methods: {
    ...mapActions({
      sendMsg: 'ws/sendMsg',
      initWS: 'ws/initWS'
    })
  }
}
